package com.leiqichao.backend.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leiqichao.backend.entity.Comment;
import com.leiqichao.backend.mapper.CommentMapper;
import com.leiqichao.backend.service.CommentService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService {
    private final CommentMapper commentMapper;
    public CommentServiceImpl(CommentMapper commentMapper) {
        this.commentMapper = commentMapper;
    }

    @Override
    public List<Comment> getCommentTree(Long articleId) {
        return commentMapper.selectCommentTree(articleId);
    }

    @Transactional
    @Override
    public boolean batchApprove(List<Long> commentIds) {
        return commentMapper.batchUpdateStatus(commentIds, "approved") > 0;
    }

    @Transactional
    @Override
    public boolean markAsSpam(List<Long> commentIds) {
        return commentMapper.batchUpdateStatus(commentIds, "spam") > 0;
    }
}